<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">组织名称</label>
        <el-input v-model="query.deptName" clearable placeholder="组织名称" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">领卡人</label>
        <el-input v-model="query.customerName" clearable placeholder="领卡人" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">激活状态</label>
        <el-select
          v-model="query.activateStatus"
          clearable
          size="small"
          placeholder="状态"
          class="filter-item"
          style="width: 130px"
          @change="crud.toQuery"
        >
          <el-option
            v-for="item in dict.activate_status"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="90px">
          <el-form-item label="编码">
            <el-input v-model.trim="form.deptId" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="组织名称">
            <el-input v-model.trim="form.deptName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="领卡人">
            <el-input v-model.trim="form.customerName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="领卡人电话">
            <el-input v-model="form.customerPhone" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="卡号">
            <el-input v-model.trim="form.cardNo" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="卡面值(元)">
            <el-input v-model="form.cardAmount" type="number" style="width: 370px;" />
          </el-form-item>
          <el-form-item v-if="crud.status.add ===0" label="领卡时间">
            <el-date-picker v-model="form.receiveTime" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item v-if="crud.status.add ===0" label="激活状态">
            <el-select v-model="form.status" filterable placeholder="请选择" style="width: 100%;">
              <el-option
                v-for="item in dict.activate_status"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item v-if="crud.status.add ===0" label="学习卡状态">
            <el-select v-model="form.cardStatus" filterable placeholder="请选择" style="width: 100%;">
              <el-option
                v-for="item in dict.card_status"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item v-if="crud.status.add ===0" label="核对状态">
            <el-select v-model="form.approveStatus" filterable placeholder="请选择" style="width: 100%;">
              <el-option
                v-for="item in dict.approve_status"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item v-if="crud.status.add ===0" label="核对时间">
            <el-date-picker v-model="form.approveTime" type="datetime" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model.trim="form.remark" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="编号">
            <el-input v-model.trim="form.id" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="deptId" label="编码" />
        <el-table-column prop="deptName" label="组织名称" />
        <el-table-column prop="customerName" label="领卡人" />
        <el-table-column prop="customerPhone" label="领卡人电话" />
        <el-table-column prop="cardNo" label="卡号" />
        <el-table-column prop="cardAmount" label=" 卡面值(元)" />
        <el-table-column prop="receiveTime" label="领卡时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.receiveTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="激活状态">
          <template slot-scope="scope">
            {{ dict.label.activate_status[scope.row.status ] }}
          </template>
        </el-table-column>
        <el-table-column prop="cardStatus" label="学习卡状态">
          <template slot-scope="scope">
            {{ dict.label.card_status[scope.row.cardStatus ] }}
          </template>
        </el-table-column>
        <el-table-column prop="approveStatus" label="核对状态">
          <template slot-scope="scope">
            {{ dict.label.approve_status[scope.row.approveStatus ] }}
          </template>
        </el-table-column>
        <el-table-column prop="approveTime" label="核对时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.approveTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="备注" />
        <el-table-column prop="id" label="编号" />
        <el-table-column v-permission="['admin','cardApprove:edit','cardApprove:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudCardApprove from '@/api/card/cardApprove'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { deptName: null, deptId: null, customerId: null, customerName: null, customerPhone: null, cardNo: null, cardAmount: null, receiveTime: null, status: null, cardStatus: null, approveStatus: null, approveTime: null, remark: null, id: null }
export default {
  name: 'CardApprove',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['activate_status', 'approve_status', 'card_status'],
  cruds() {
    return CRUD({ title: 'approveCard', url: 'api/cardApprove', idField: 'id', sort: 'id,desc', crudMethod: { ...crudCardApprove }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'cardApprove:add'],
        edit: ['admin', 'cardApprove:edit'],
        del: ['admin', 'cardApprove:del']
      },
      rules: {
      }}
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    [CRUD.HOOK.beforeToEdit](a, b) {
      this.form.cardStatus = this.form.cardStatus + ''
      this.form.status = this.form.status + ''
      this.form.approveStatus = this.form.approveStatus + ''
      // b.cardAmount = b.cardAmount / 100
      return true
    }
  }
}
</script>

<style scoped lang="scss">
  .head-container {
    /** 去除input输入框样式 */
    ::v-deep input[type=number]::-webkit-inner-spin-button {
      -webkit-appearance: none;
    }
	::v-deep input[type="number"] {
	    -moz-appearance:textfield;
	}
  }
</style>
